package weixin.core.Handles;

import com.github.sd4324530.fastweixin.api.TemplateMsgAPI;
import com.github.sd4324530.fastweixin.api.entity.TemplateMsg;
import com.github.sd4324530.fastweixin.api.entity.TemplateParam;
import com.github.sd4324530.fastweixin.api.response.SendTemplateResponse;
import com.github.sd4324530.fastweixin.handle.EventHandle;
import com.github.sd4324530.fastweixin.message.BaseMsg;
import com.github.sd4324530.fastweixin.message.TextMsg;
import com.github.sd4324530.fastweixin.message.req.MenuEvent;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * Created by lxb on 2016/4/8.
 */
@Component
public class MyMenuEvent implements EventHandle<MenuEvent> {
    private static final Logger LOG  = LoggerFactory.getLogger(MyMenuEvent.class);
    @Autowired
    private TemplateMsgAPI templateMsgAPI;
    public BaseMsg handle(MenuEvent event) {
        LOG.info("接收到的事件："+event);
        TemplateMsg templateMsg=new TemplateMsg();
        Map<String,TemplateParam> map=new HashMap();
        TemplateParam templateParam=new TemplateParam();
        templateParam.setColor("#173177");
        templateParam.setValue("测试值");
        map.put("001", templateParam);
        templateMsg.setData(map);
        templateMsg.setTemplateId("VdETzsrXDROxfpR4yAncWe35eU8i7GR9Ai88TV-0O4s");
        templateMsg.setTouser(event.getFromUserName());
        templateMsg.setTopcolor("#173177");
        templateMsg.setUrl("http://www.baidu.com");
        SendTemplateResponse sendTemplateResponse=templateMsgAPI.send(templateMsg);
        return new TextMsg("点击菜单了");
    }

    public boolean beforeHandle(MenuEvent event) {
        return false;
    }


}
